﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using DigitalRune.Windows.TextEditor;
using DigitalRune.Windows.TextEditor.Completion;


namespace EdgeStatz.DesignTools
{
    class CodeCompletionDataProvider : AbstractCompletionDataProvider
    {
        private readonly ImageList _imageList;

        public override ImageList ImageList
        {
            get { return _imageList; }
        }

        public CodeCompletionDataProvider()
        {
            // Create the image-list that is needed by the completion windows
            _imageList = new ImageList();
            _imageList.Images.Add(DesignerResources.img24_VSObject_Map);
            _imageList.Images.Add(DesignerResources.img24_VSObject_Field);
            _imageList.Images.Add(DesignerResources.img24_VSObject_Method);
            _imageList.Images.Add(DesignerResources.img24_VSObject_Class);
            _imageList.TransparentColor = System.Drawing.Color.Magenta;
        }


        public override ICompletionData[] GenerateCompletionData(string fileName, TextArea textArea, char charTyped)
        {
            // This class provides the data for the Code-Completion-Window.
            // Some random variables and methods are returned as completion data.

            List<ICompletionData> completionData = new List<ICompletionData>
              {
                  new DefaultCompletionData("object", "class System.object", 3),
                  new DefaultCompletionData("int", "struct System.Int32\nrepresents a 32-bit signed integer", 3),
                  new DefaultCompletionData("string", "class System.string", 3)
              };


                    // Add some snippets (text templates).
                    List<Snippet> snippets = new List<Snippet>
              {
                new Snippet("for", "for (|;;)\n{\n}", "for loop"),
                new Snippet("if", "if (|)\n{\n}", "if statement"),
                new Snippet("if else", "if (|)\n{\n}\nelse\n{\n}", "if-else statement"),
                new Snippet("while", "while (|)\n{\n}", "while loop"),
                new Snippet("switch", "switch (|)\n{\n}", "switch statement"),
                new Snippet("this","this ",""),
                new Snippet("throw","throw ",""),
                new Snippet("typeof","typeof(|)",""),
                new Snippet("null","null",""),
                new Snippet("void","void",""),
                new Snippet("return","return",""),
              };

            // Add the snippets to the completion data
            foreach (Snippet snippet in snippets)
                completionData.Add(new SnippetCompletionData(snippet, 0));

            return completionData.ToArray();
        }

    }
}
